<% layout('/layouts/default.html', {title: '轮播图管理', libs: ['validate','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(banner.isNewRecord ? '新增轮播图' : '编辑轮播图')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${banner}" action="${ctx}/storage/banner/save" method="post" class="form-horizontal">
		<div class="box-body">
			<div class="form-unit">${text('基本信息')}</div>
			<#form:hidden path="id"/>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2">${text('缩略图')}：</label>
						<div class="col-sm-10">
							<#form:hidden class="form-control" id="thumbnail" name="thumbnail" path="thumbnail"/>
							<#form:fileupload id="imagethumbnail" uploadType="image" returnPath="true" filePathInputId="thumbnail" class="form-control" readonly="false" maxUploadNum="1"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('顺序')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="sort" maxlength="255" class="form-control required digits"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('类型')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<% var types = [{type:'活动'},{type:'栏目'}]; %>
							<#form:select path="type" class="form-control" items="${types}" itemLabel="type" itemValue="type" blankOption="true" blankOptionLabel="请选择"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required hide">*</span> ${text('营销活动')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:listselect path="activityId" labelPath="activity.name" title="活动选择" url="${ctx}/storage/activity/select" allowClear="true" checkbox="false" itemCode="id" itemName="name"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required hide">*</span> ${text('栏目')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:listselect path="routeId" labelPath="route.name" title="栏目选择" url="${ctx}/storage/route/select" allowClear="true" checkbox="false" itemCode="id" itemName="name"/>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="box-footer">
			<div class="row">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
					<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
				</div>
			</div>
		</div>
	</#form:form>
</div>
</div>
<% } %>
<script>
	function chanageType(){
		$("[name='activityId']").parents(".row").hide();
		$("[name='routeId']").parents(".row").hide();
		switch ($("#type option:selected").val()) {
			case "活动":
				$("[name='activityId']").parents(".row").show();
				break;
			case "栏目":
				$("[name='routeId']").parents(".row").show();
				break;
		}
	}
	$(function () {
		$(document).on("change","#type",function () {
			chanageType();
		});
		chanageType();
	});
</script>
<script>
	$("#inputForm").validate({
		submitHandler: function(form){
			js.ajaxSubmitForm($(form), function(data){
				js.showMessage(data.message);
				if(data.result == Global.TRUE){
					js.closeCurrentTabPage(function(contentWindow){
						contentWindow.page();
					});
				}
			}, "json");
		}
	});
</script>